package com.gorkr.labuladong.data_struct.linked_list;

/**
 * @author gorkr
 * @date 2022/09/17 16:47
 **/
public class E024ReverseLinkedList {

     class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

    public ListNode reverseList(ListNode head) {
         // base case
         if(head.next==null){
             return head;
         }

        ListNode last = reverseList(head.next);
        head.next.next = head;
        head.next = null;

        return last;
    }

}
    